package com.gdit.zax.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.LogUtil;
import com.gdit.zax.utils.webUtil;

public class hello extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String sql = "select count(t.id),sum(l.id),now() from  t_user as t inner join t_login as l on l.UserId=t.Id where t.Id = 137";
		
		try {
			PreparedStatement ps = DBUtil.getConnection().prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while(rs.next()) {
				ResultSetMetaData rd = rs.getMetaData();
				for (int i = 1; i <= rd.getColumnCount(); i++) {
					String fieldname =  rd.getTableName(i) + "_" + rd.getColumnName(i);
					System.out.println("fieldname:" + fieldname + ">>" + rs.getString(i));
				}
			}
			
		} catch (SQLException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		
		
		
		
		
		StringBuffer sb = new StringBuffer();
		
		sb.append("=====================header data========================<br>");
		Enumeration e = request.getHeaderNames();
		while (e.hasMoreElements()) {
			Object obj = e.nextElement();
			sb.append(obj + " = " + request.getHeader(obj.toString()) + "<br>");
		}
		
		sb.append("=====================Parameter data========================<br>");
		Enumeration e1 = request.getParameterNames();
		
		while (e1.hasMoreElements()) {
			Object obj = e1.nextElement();
		}
	
		sb.append("=====================end========================<br>");
		
		PrintWriter out = response.getWriter();
		webUtil.printParameter(request);
		out.print(sb.toString());
		out.flush();
		out.close();
	}

}
